package com.zhengbing.tj.design.singleton;

/**
 * 双重检查锁定单例模式实现类
 * 特点：首次调用时初始化实例，通过双重检查和volatile关键字保证线程安全和性能
 * 
 * @author zhengbing
 * @date 2025-07-23
 */
public class DoubleCheckedLockingSingleton {
    private static volatile DoubleCheckedLockingSingleton instance;

    private DoubleCheckedLockingSingleton() {}

    // 双重检查锁定实现
    public static DoubleCheckedLockingSingleton getInstance() {
        if (instance == null) {
            synchronized (DoubleCheckedLockingSingleton.class) {
                if (instance == null) {
                    instance = new DoubleCheckedLockingSingleton();
                }
            }
        }
        return instance;
    }

    public void showMessage() {
        System.out.println("Double Checked Locking Singleton Instance");
    }
}